package common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/***
 * 日期工具类
 * @author lby
 *
 */
public class DateUtil
{
	/***
	 * 把date变成字符串
	 * @param now
	 * @return
	 */
	public String dateTime(Date now)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(ConstatFinalUtil.DATE_TIME_FORMAT);
		return sdf.format(now) ; 
	}
	/***
	 * 把字符串转换成Date
	 * @param str
	 * @return
	 */
	public Date strToDateTime(String str)
	{
		try
		{
			SimpleDateFormat sdf = new SimpleDateFormat(ConstatFinalUtil.DATE_TIME_FORMAT);
			return sdf.parse(str) ;
		} catch (ParseException e)
		{
		} 
		return null ; 
	}
	public String dateToStr(Date now)
	{
		SimpleDateFormat sdf = new SimpleDateFormat(ConstatFinalUtil.DATE_FORMAT);
		return sdf.format(now) ;
	}
}
